﻿using God.ShoppingWebApi.DTO;
using God.ShoppingWebApi.Entities;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace God.ShoppingWebApi.WebAdmin
{
    /// <summary>
    /// 角色用户表
    /// </summary>
    public class AdminRoleUserService : ApplicationService, IAdminRoleUserService
    { 
        IRepository<UserRoles, Guid> _userroles;
  

        public AdminRoleUserService(IRepository<UserRoles, Guid> userroles)
        {
            _userroles = userroles;
         
        }
        [Route("api/UserRoleAdd")]
        /// <summary>
        /// 添加用户角色
        /// </summary>
        /// <param name="roleUsers"></param>
        /// <returns></returns>
        public async Task AddAsync(RoleUsersDTO roleUsersDTO)
        {
            var a = new UserRoles();
            a.RoleId = roleUsersDTO.RoleId;
            a.UserId = roleUsersDTO.UserId;
            await _userroles.InsertAsync(a);
        }
        [Route("api/UserRoleDel")]
        /// <summary>
        /// 删除用户角色
        /// </summary>
        /// <param name="gu"></param>
        /// <returns></returns>
        public async Task DeleteAsync(Guid gu)
        {
            await _userroles.DeleteAsync(gu);
        }
        [Route("api/UserRoleShow")]
        /// <summary>
        /// 角色用户显示
        /// </summary>
        /// <returns></returns>
        public async Task<List<RoleUsersDTO>> GetListAsync()
        {
            var str = await _userroles.GetListAsync();

            return ObjectMapper.Map<List<UserRoles>, List<RoleUsersDTO>>(str);
        }
       
    }
}
